package com.songlanyun.modules.payorder.service;

import com.alibaba.fastjson.JSONObject;
import com.songlanyun.common.drive.IBaseService;
import com.songlanyun.common.enums.GoodsConstant;
import com.songlanyun.common.enums.OrderConstant;
import com.songlanyun.common.utils.PageUtils;
import com.songlanyun.common.utils.R;
import com.songlanyun.modules.coupon.model.vo.CouponEntityVo;
import com.songlanyun.modules.order.entity.Order;
import com.songlanyun.modules.order.model.dto.SubmitOrderUseCoupon;
import com.songlanyun.modules.order.model.vo.PayOrderDetailVo;
import com.songlanyun.modules.payorder.entity.PayOrder;
import com.songlanyun.modules.payorder.model.dto.*;
import com.songlanyun.pay.bean.PayBean;
import com.songlanyun.pay.common.api.ApiResult;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 用来聚合支付的订单
 *
 * @author lubo
 * @email sunlightcs@gmail.com
 * @date 2020-11-17 09:16:34
 */
public interface PayOrderService extends IBaseService<Long, PayOrder> {


    @Override
    PageUtils queryPage(Map<String, Object> params);

    PageUtils queryPageAll(Map<String, Object> params);

    PayOrder initPayOrder(Long userId, BigDecimal totalMoney, OrderConstant.PayMode payMode, OrderConstant.OrderType orderType);

    PayOrder initPayOrderForSale(Long userId, BigDecimal totalMoney, BigDecimal totalReduced, OrderConstant.PayMode payMode, OrderConstant.OrderType orderType, List<String> goodsImages, Long expiredPayTime, SubmitOrderUseCoupon platformCoupon,GoodsConstant.AreaFeature areaFeature);

    PayOrder initPayOrderForSaleAndPoint(Long userId, BigDecimal totalMoney, BigDecimal totalReduced, BigDecimal totalPoint, OrderConstant.PayMode payMode, OrderConstant.OrderType orderType, List<String> goodsImages, Long expiredPayTime, SubmitOrderUseCoupon platformCoupon, GoodsConstant.AreaFeature areaFeature);

    PayOrder paymentHandle(String payOrderCode, String thirdPayCode, BigDecimal returnMoney,OrderConstant.PayMode payMode);

    /**
     * 支付宝成功支付后调用,所有安全校验必须之前处理完成才可以调用，来处理充值成功后的事情
     *
     * @param payOrderCode 订单号
     * @param thirdPayCode 第三方单号(退款)
     * @param receiptAmount  实收金额。商家在交易中实际收到的款项，单位为人民币（元），精确到小数点后 2 位
     * @param buyerPayAmount  用户在交易中支付的金额，单位为人民币（元），精确到小数点后 2 位
     * @return 更新后的支付订单实体
     */
    PayOrder paymentHandleForAliPay(String payOrderCode, String thirdPayCode, BigDecimal receiptAmount, BigDecimal buyerPayAmount,OrderConstant.PayMode payMode);

    void uploadOrder(PayOrder payOrder);

    PayOrder paymentFailHandle(String payOrderCode, String thirdPayCode, BigDecimal returnMoney, OrderConstant.PayMode payMode);

    PayOrder getByCode(String payOrderCode, Boolean tw);

    void uploadOrderEvent(Order order);

    /**
     * 支付
     * @param orderNo   支付单号
     * @param amount    金额
     * @param openId    openid
     * @param payType   支付类型
     * @return
     */
    ApiResult pay(String orderNo, String amount, String openId, Integer payType);

    ApiResult pay(String orderNo, String amount, String openId, Integer payType,String description);

    /**
     * 汇付
     * @param orderNo
     * @param amount
     * @param goodsTitle
     * @param goodsDesc
     * @param payType
     * @param description
     * @return
     */
    ApiResult pay(String orderNo, String amount, String goodsTitle,String goodsDesc, Integer payType,String description);

    /**
     * 快捷支付
     * @param orderNo
     * @param tokenNo
     * @param amount
     * @param goodsTitle
     * @param goodsDesc
     * @param payType
     * @param description
     * @return
     */
    ApiResult pay(String orderNo,String tokenNo, String amount, String goodsTitle,String goodsDesc, Integer payType,String description);

    ApiResult pay(String orderNo, String amount, Integer payType, String description, String longitude, String latitude, String validCode);

    /**
     * 慧收钱
     * @param orderNo       订单号
     * @param amount        金额
     * @param payType       支付类型
     * @param description   商品说明
     * @param longitude     经度
     * @param latitude      纬度
     * @return
     */
    ApiResult pay(String orderNo, String amount, Integer payType, String description,  String longitude, String latitude);

    PayOrder getByUserIdAndId(Long userId,Long payOrderId,Boolean tw);

    List<PayOrder> getExpiredOrder(long timeMillis);

    PayOrderDetailVo getPayOrderSakeDetail(Long userId, Long payOrderId);

    /**
     * 检验关闭订单
     * @param payOrder
     */
    void verifyCloseOrder(PayOrder payOrder);

    Integer waitPayNum(Long userId,OrderConstant.OrderType type,Integer areaFeature);

    Map<String, Object> kjPayConfirm(AdaPayKJPayConfirmDTO dto);

    Map<String, Object> payRepeatSendSms(AdaPayKJPayConfirmDTO dto);

    R getCardInfo(JSONObject req)throws Exception;

    R getUserBankInfo(KqUserBankInfoReqDTO req);

    R firstBindingCard(KqFirstCertificationReqDTO req)throws Exception;

    R kqPayApply(KqPayApplyReqDTO req) throws Exception;

    R closeVerify(KqCloseVerifyReqDTO req);
}

